import cv2 as cv
image = cv.imread(r'C:\Users\Admin\Desktop\retif/7_11.png',0)
#  16:9
list = []
for i in range(360//3-2):
    for j in range(480//3-2):
        list.append([i, j])
        print(i,j,end='\t')
    print('\n')
for x,y in list:
    avge_3 = [[0],[0],[0],[0],[0],[0],[0],[0],[0]]
    sum_3 = [[0],[0],[0],[0],[0],[0],[0],[0],[0]]
    sum_9 = 0
    min =255
    max = 0
    for i in range(9):
        for j in range(9):
            sum_3[i//3*3+j//3] += image[x*3+i][y*3+j]
            sum_9 += image[x*3+i][y*3+j]
            if min > image[x*3+i][y*3+j]:
                min = image[x * 3 + i][y * 3 + j]

    sum_9 //= (9*9)
    min=sum_3[4]
    flag=0
    avg_sum_3 = 0
    for i in range(9):
        if i == 4:
            continue
        avg_sum_3 += sum_3[i]

    avg_sum_3 = avg_sum_3 / 8


    if avg_sum_3 >= min:
        if avg_sum_3-min>100:

            flag=1
    #         continue
    # else:
    #     flag=0
    if flag:
        image[x * 3 + 4][y * 3 + 4] = 0
        image[x * 3 + 3][y * 3 + 4] = 0
        image[x * 3 + 5][y * 3 + 4] = 0
        image[x * 3 + 4][y * 3 + 3] = 0
        image[x * 3 + 4][y * 3 + 5] = 0
        print("zero")

cv.imshow("123",image)
cv.imwrite(r'C:\Users\Admin\Desktop\reimage/0_0.png',image)
cv.waitKey(0)
print('')
